<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //原型的继承

      //父类构造函数
      function Dad(name, age) {
        this.name = name;
        this.age = age;
        // this.fn = function () {
        //   console.log("fn");
        // };//不同的函数提取fn都不同
      }
      Dad.prototype.fn = function () {
        console.log("fn");
      };
      var zhangsan = new Dad("张三", 20);
      zhangsan.fn();
      var lisi = new Dad("李四", 21);
      lisi.fn();
      console.log(zhangsan.fn === lisi.fn);

      //
      //
      //
      //子类构造函数
      function Son(name, age) {
        Dad.call(this, name, age);
      }

      //
      //继承原型: 会造成引用问题,子类原型和父类原型  会相互影响
      //   Son.prototype = Dad.prototype;

      //组合继承,切断子类原型和父类原型之间的引用关系
      function Link() {
        Link.prototype = Dad.prototype;
        Son.prototype = new Link();

        //
        Son.prototype.fn = function () {
          //把子类fn重新写了
          console.log("son里的fn");
        };
        var son = new Son("张四", 50);
        console.log(son);
        son.fn();
      }
      var dad = new Dad("张三", 52);
      dad.fn();
    </script>
  </body>
</html>
